/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package overload;

/**
 *
 * @author benjamin
 */
public class Appel {

    public static int NUMBERCREATEDCALL;
    public static int NUMBERPROCESSEDCALL;
    public static int NUMBEROFGIVENUPCALL;
    public static int NUMBEROFREFUSEDCALLWITHOUTPROCESSING;
    public static int NOMBEROFFORWARDEDCALL;
    public static int NUMBEROFREATTEMPTEDCALL;
    public static int NUMBEROFREATTEMPTEDANDFAILEDCALL;
    public static int NUMBEROFCALLINTERVAL;
    
    public static int TIME_CALL_REATTEMPTED_PREVIOUS;
    public static int TIME_CALL_REATTEMPTED_ACTIVE;
    
    public static int TIME_CALL_AGR_PREVIOUS;
    public static int TIME_CALL_AGR_ACTIVE;
    
    public static int TIME_CALL_REALEASE_PREVIOUS;
    public static int TIME_CALL_REALEASE_ACTIVE;
    
    public static int inputQueue[] = new int[5000];
    public static int inputQueueReattempted[]= new int[1000000];
    public static int inputCallRealease[]= new int [1000000];
    public static int agreTraffic[]=new int[1000000];
    

    
    public int timeCreation;
    public int timeBegin;
    public int timeProcessed;
    public int timeEnd;
    public int tolerance;
    public int nbTry;
    public int timeReattempt;
    public boolean ineffective;
    public boolean toGiveUp;
    public boolean finished;
    public int duration;
    
    public Appel(int time, int duree){
        
        this.finished=false;
        this.toGiveUp=false;
        this.ineffective=false;
        Appel.NUMBERCREATEDCALL++;
        Appel.NUMBEROFCALLINTERVAL++;
        this.tolerance=(int)(2000+4000*Math.random());
        this.timeCreation=time;
        this.timeBegin=time;
        this.duration=duree;
        this.timeEnd=time+this.duration;
        this.nbTry=0;
        
    }
    
    //Used when the call begin
    public void debutAppel(int time){
        this.timeProcessed=time;
        Appel.NOMBEROFFORWARDEDCALL++;
        
    }
    
    //statistics purposes for the aggregate traffic
    public static void addAggrStat(int time){
     /*   Appel.TIME_CALL_AGR_PREVIOUS=Appel.TIME_CALL_AGR_ACTIVE;
        Appel.TIME_CALL_AGR_ACTIVE=time;
        Appel.agreTraffic[Appel.TIME_CALL_AGR_ACTIVE-Appel.TIME_CALL_AGR_PREVIOUS]++;*/
    }
    
    //statistics purpose for the released call
    public static void addRealStat(int time){
       /*  Appel.TIME_CALL_REALEASE_PREVIOUS=Appel.TIME_CALL_REALEASE_ACTIVE;
         Appel.TIME_CALL_REALEASE_ACTIVE=time;
         Appel.inputCallRealease[Appel.TIME_CALL_REALEASE_ACTIVE-Appel.TIME_CALL_REALEASE_PREVIOUS]++;*/
        
    }
    
    //choice of a new time of reatttempt after having failed
    public void  setTimeReattempt1(int time){
     this.timeReattempt = (int) (30000 + 90000 *Math.random())+time;
        this.timeBegin =this.timeReattempt;
        this.timeEnd=this.timeReattempt+this.duration;
        Appel.NUMBEROFREATTEMPTEDCALL++;
    }
    
    //Call refused
    
    public void rejectCall(){
        Appel.NUMBEROFREFUSEDCALLWITHOUTPROCESSING++;
    }
    
     //choice of a new time of reatttempt after having failed   
public void  setTimeReattempt2(int time){
       this.timeReattempt = (int) (80000 + 160000 *Math.random())+time;
        this.timeBegin = this.timeReattempt;
        this.timeEnd=this.timeReattempt+this.duration;
}
    
    //when a call is finisehd and processed
    public void  terminationCall(){
        Appel.NUMBERPROCESSEDCALL++;        
    }
    
    //call given up
    public void giveUpCall(){
        this.toGiveUp=true;
        Appel.NUMBEROFGIVENUPCALL++;
        Appel.NUMBEROFREATTEMPTEDANDFAILEDCALL++;
    }
    
}
